Repository navigation
fix(artists): cache popular-artists fallback in Redis (suggestions empty bug) - #707
Conversation
Spotify search API rate-limits us (429) when every page load fans out
to 8+ search queries. Symptom: /api/artists/suggestions returns
{artists:[]} → page shows 'No suggestions available' even though the
endpoint reports 200.
Cache the fallback bundle in Redis with a 1h TTL keyed by version.
First request populates, subsequent reads bypass Spotify entirely.
Also bumped the query list from 8 → 12 popular artists.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 37 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant API as API Route
participant Redis
participant Spotify as Spotify API
Client->>API: GET /api/artists/suggestions
alt Popular Artists Fallback Needed
API->>Redis: get(POPULAR_ARTISTS_KEY)
alt Cache Hit
Redis-->>API: cached artist bundle
else Cache Miss
API->>Spotify: Multiple searchSpotifyArtists queries
Spotify-->>API: artist results
API->>API: deduplicate by ID
API->>Redis: setex(POPULAR_ARTISTS_KEY, 3600, artists)
Redis-->>API: OK
end
API->>API: merge artists into suggestions (up to 24 total)
end
API-->>Client: suggestions response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/backend/src/routes/artists.ts`:
- Around line 126-132: The Redis-cached payload read via
redisClient.get(FALLBACK_SUGGESTIONS_CACHE_KEY) is used without validating its
shape, so a non-array or malformed JSON will cause fallback.length/iteration
errors; update the try blocks around redisClient.get(...) (and the similar code
near lines handling the same key) to JSON.parse the cached value then verify
it's an array of SpotifyArtist-like objects (e.g., Array.isArray(parsed) and
optional checks for expected fields) before assigning to the fallback variable;
if validation fails, ignore the cache (leave fallback as the live-fetch
sentinel) and proceed to fetch from Spotify to prevent 500s.
- Around line 137-181: The fallback-population code currently lets concurrent
requests run the 12-query loop and can cache partial results; fix by using a
Redis single-flight lock via redisClient.setNxPx() on
FALLBACK_SUGGESTIONS_CACHE_KEY (or a derived lock key) before running the
suggestQueries loop so only one process populates at a time, have other callers
detect the lock (read the cache in a short retry/backoff loop and return cached
value if populated), and only call redisClient.setex to cache results if
fallback.length meets a minimum threshold (e.g., >= 24 or a configurable
populationThreshold); always release the lock (delete the lock key) in a finally
block and on failures avoid caching partial results or use a much shorter TTL
variable instead of FALLBACK_SUGGESTIONS_TTL_SECONDS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3bbfb3a5-c436-41ba-93b8-d4da68cec8b9
📒 Files selected for processing (1)
packages/backend/src/routes/artists.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Quality Gates
- GitHub Check: SonarCloud Scan
🔇 Additional comments (1)
packages/backend/src/routes/artists.ts (1)
16-19: LGTM: cache dependency and TTL are scoped cleanly.The fixed key and 1-hour TTL match the fallback-bundle caching objective.
|
…pty bug) (#707) * fix(artists): cache popular-artists fallback in Redis (1h) Spotify search API rate-limits us (429) when every page load fans out to 8+ search queries. Symptom: /api/artists/suggestions returns {artists:[]} → page shows 'No suggestions available' even though the endpoint reports 200. Cache the fallback bundle in Redis with a 1h TTL keyed by version. First request populates, subsequent reads bypass Spotify entirely. Also bumped the query list from 8 → 12 popular artists. * test(backend): mock redisClient for artists suggestions cache



Bug
/api/artists/suggestionsreturns{"artists":[]}on production. Page shows 'No suggestions available'.Root cause
Spotify search API returns 429 (rate-limited). Each page load fans out 8+ search calls (Drake, The Weeknd, Dua Lipa, etc.). Without caching, this saturates Spotify quota fast and starts returning empty.
Fix
Cache the popular-artists fallback bundle in Redis (key
artist:suggestions:fallback:v1, TTL 1h). First request populates, subsequent reads bypass Spotify. Also bumped the query list from 8 → 12 artists for variety.Summary by CodeRabbit